package stanpayng

import (
	"github.com/zeromicro/go-zero/core/logc"
	"net/http"

	"gitee.com/liuxuezhan/ar-platform/assets-api/internal/logic/pay/stanpayng"
	"gitee.com/liuxuezhan/ar-platform/assets-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/assets-api/internal/types"
	"github.com/zeromicro/go-zero/rest/httpx"
)

// stanpayng代收回调通知
func StanPayNgPaymentNotifyHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		logc.Info(r.Context(), r)
		var req types.StanPayNgCallbackRequest
		if err := httpx.Parse(r, &req); err != nil {
			logc.Error(r.Context(), err)
			w.Write([]byte(err.Error()))
			return
		}

		l := stanpayng.NewStanPayNgPaymentNotifyLogic(r.Context(), svcCtx)
		_, err := l.StanPayNgPaymentNotify(&req)
		if err != nil {
			logc.Error(r.Context(), err)
			httpx.ErrorCtx(r.Context(), w, err)
		} else {
			w.Write([]byte("SUCCESS"))
			return
		}
	}
}
